package primetest.impl.service;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;

import primetest.dto.RatingTypeDto;
import primetest.impl.dao.RatingTypeDao;
import primetest.impl.dao.Transaction;
import primetest.impl.service.RatingTypeService;

public class RatingTypeService implements  Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -8060430686329121620L;
	private Transaction transaction;
	private RatingTypeDao ratingTypeDao;

	@Inject
	public RatingTypeService(Transaction transaction,RatingTypeDao officeDao){
		this.transaction = transaction;
		this.ratingTypeDao = officeDao;
	}
	
	public List<RatingTypeDto> getRatingTypeList() throws IOException {
		try{
			transaction.begin();
			List<RatingTypeDto> officeList = ratingTypeDao.getRatingTypeList(transaction);
			transaction.commit();
			return officeList;
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}
	
	public RatingTypeDto getRatingType(int ratingTypeSeq) throws IOException {
		try{
			transaction.begin();
			RatingTypeDto ratingTypeDto = ratingTypeDao.getRatingType(transaction, ratingTypeSeq);
			transaction.commit();
			return ratingTypeDto;
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public void addRatingType(Transaction transaction, RatingTypeDto officeDto) throws IOException {
		try{
			transaction.begin();
			ratingTypeDao.addRatingType(transaction, officeDto);
			ratingTypeDao.getRatingTypeList(transaction);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public void updateRatingType(Transaction transaction, RatingTypeDto officeDto) throws IOException {
		try{
			transaction.begin();
			ratingTypeDao.updateRatingType(transaction, officeDto);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

	
	public void deleteRatingType(Transaction transaction, int officeSeq) throws IOException {
		try{
			transaction.begin();
			ratingTypeDao.deleteRatingType(transaction, officeSeq);
			ratingTypeDao.getRatingTypeList(transaction);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}
}
